<template>
    <div class="bg">
        <div class="notRecord" v-if="videos.length === 0">
            <p>暂无创作视频</p>
        </div>
        <div class="overRecord videoUl" v-else>
            <div class="videoColumn">
                <div v-for="item in videos" :key="item.videoId" class="videoBox">
                    <p v-if="item.code === 0" class="failureBox">
                        失败
                        <van-icon color="white" @click="deleteVideo(item)" name="delete" />
                    </p>
                    <div v-else class="successBox">
                        <video :src="item.videoUrl"></video>
                        <div class="buttonContainer">
                            <button class="regenerateButton" @click="regenerateVideo(item)">再次生成</button>
                            <van-icon color="white" @click="deleteVideo(item)" name="delete" />
                        </div>  
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import {ref} from 'vue'
import { useRoute, useRouter } from 'vue-router';
import { useNoloStore } from '../../store';
import { ROUTER_NAME_SELECT_IMG_PAGE } from "../../route";
const store = useNoloStore();
const router = useRouter();
const route = useRoute();
let videos = ref(JSON.parse(localStorage.getItem('videos')) || []);

const regenerateVideo = (item) => {
    // 在这里添加重新生成指定视频的逻辑，可以使用 item.videoId 等来识别和处理
    router.push({
        name:ROUTER_NAME_SELECT_IMG_PAGE
    });
};

const deleteVideo = (item) => {
    // 在这里添加删除指定视频的逻辑，可以使用 item.videoId 等来识别和处理
    videos.value = videos.value.filter(video => video.videoId!== item.videoId);
    localStorage.setItem('videos', JSON.stringify(videos.value));
};
</script>

<style scoped lang="less">
@import url(../../style/index.less);

.bg {
    position: relative;
    background-color: black;
    height: 100vh;
    width: 100vw;
    // padding-top: 34px;
    padding-bottom: 130px;
    color: white;
    display: flex;
    justify-content: center;
    align-items: flex-start; /* 顶部对齐 */
}
.notRecord {
    text-align: center;
    top: 60%;
    position: relative;
}
.videoUl {
    display: flex;
    justify-content: center;
    flex-direction: column; /* 垂直方向布局 */
    width: 100%;
    margin-top: 20px; /* 顶部留出一定间距 */
}

.videoColumn {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 90%;
    max-width: 1200px;
    margin: 0 auto;
}

.videoBox {
    width: 100%;
    box-sizing: border-box;
    padding: 0; /* 去掉内边距 */
    text-align: center;
    position: relative; /* 确保定位元素相对于该元素 */
}

.failureBox {
    height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.successBox {
    height: 200px;
    position: relative;
}

video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px; /* 圆角 */
    margin-bottom: 10px;
}

.buttonContainer {
    position: absolute;
    bottom: 10px; /* 调整按钮容器与视频底部的距离 */
    left: 0;
    right: 0;
}

.regenerateButton {
    padding: 5px 10px;
    background-color: #000;
    color: white;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    font-size: 14px;
    margin: 0 5px; /* 调整按钮之间的间距 */
}
.deleteButton {
    padding: 5px 10px;
    color: white;
    // border: none;
    // border-radius: 4px;
    // cursor: pointer;
    // font-size: 14px;
    margin: 0 5px; /* 调整按钮之间的间距 */
}
.regenerateButton:hover, .deleteButton:hover {
    background-color: #0056b3;
}

.regenerateButton:focus, .deleteButton:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.5); /* 添加聚焦时的边框阴影效果 */
}
</style>
